package com.jbm.jbmsupplier.activity.loadhomepage.mode

import com.jbm.enterapplication.InterfaceMa
import com.jbm.enterapplication.InterfaceMaArr
import com.jbm.jbmsupplier.activity.rxjavanet.ModeRxjavaNet
import com.jbm.onehome.iface.IOrderCtrl
import com.jbm.onehome.iface.IorderEntity
import rx.Observable
import rx.Observer

/**
 * Created by 家帮忙 on 2017/8/23.
 */
class ListFrement_Mode :ListRement_Mode_Inte<String,IorderEntity>{
    override fun LoadDateConstrus(tag: Int, static: String, onclicklinner: InterfaceMaArr<String, IorderEntity>) {
         val num = 5
        if (tag==3){
            page=0
        }else if (tag==4){
            page+=5
        }else if (tag==5){
            page+=5
        }
        ModeRxjavaNet.getInstantMode().objects(Observable.create(Observable.OnSubscribe <IOrderCtrl>{
            iordeobser->
                iordeobser.onNext(ModeRxjavaNet.getInstantMode().getOhInter().GetOrderListTempWY(null, null, page, num))

        })).subscribe(object : Observer<IOrderCtrl> {
            override fun onCompleted() {
            }
            override fun onError(e: Throwable?) {

            }

            override fun onNext(t: IOrderCtrl?) {
                var listorder=ArrayList<IorderEntity>();
                if (t?.m_code==200){
                    if (page==0){
                        listorder.clear()
                        onclicklinner.onSuccess("0",true,listorder)
                        if (t?.orderList!=null){
                            if(t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("1",true,listorder)}
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }else{
                        if (t?.orderList!=null){
                            if (t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("2",true,listorder)}
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }
                }else {
                    onclicklinner.setError(t?.m_info!!,false)
                }

            }

        })
    }

    override fun LoadDateguidang(tag: Int, static: String, onclicklinner: InterfaceMaArr<String, IorderEntity>) {
         val num = 5
        if (tag==3){
            page=0
        }else if (tag==4){
            page+=5
        }else if (tag==5){
            page+=5
        }

        ModeRxjavaNet.getInstantMode().objects(Observable.create(Observable.OnSubscribe <IOrderCtrl>{
            iordeobser->
                iordeobser.onNext(ModeRxjavaNet.getInstantMode().getOhInter().GetOrderListOtherWY(null, null, page, num))

        })).subscribe(object : Observer<IOrderCtrl> {
            override fun onCompleted() {

            }

            override fun onError(e: Throwable?) {

            }

            override fun onNext(t: IOrderCtrl?) {
                var listorder=ArrayList<IorderEntity>();
                if (t?.m_code==200){
                    if (page==0){
                        listorder.clear()
                        onclicklinner.onSuccess("0",true,listorder)
                        if (t?.orderList!=null){
                            if(t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("1",true,listorder)}
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }else{
                        if (t?.orderList!=null){
                            if (t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("2",true,listorder)
                            }
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }
                }else {
                    onclicklinner.setError(t?.m_info!!,false)
                }

            }

        })


    }

    override fun LoadDateJBM(tag: Int, static: String, onclicklinner: InterfaceMaArr<String, IorderEntity>) {

        ModeRxjavaNet.getInstantMode().objects(Observable.create(Observable.OnSubscribe <IOrderCtrl>{
            iordeobser->
             val num = 5
            if (tag==3){
                page=0
            }else if (tag==4){
                page+=5
            }else if (tag==5){
                page+=5
            }
                iordeobser.onNext(ModeRxjavaNet.getInstantMode().getOhInter().GetOrderListJBMWY(null, null, page, num))

        })).subscribe(object : Observer<IOrderCtrl> {
            override fun onCompleted() {

            }

            override fun onError(e: Throwable?) {

            }

            override fun onNext(t: IOrderCtrl?) {
                var listorder=ArrayList<IorderEntity>();
                if (t?.m_code==200){
                    if (page==0){
                        listorder.clear()
                        onclicklinner.onSuccess("0",true,listorder)
                        if (t?.orderList!=null){
                            if(t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("1",true,listorder)}
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }else{
                        if (t?.orderList!=null){
                            if (t?.orderList.size>0){
                                listorder.addAll(t.orderList)
                                onclicklinner.onSuccess("2",true,listorder)}
                        }else{
                            onclicklinner.onSuccess("0",false,listorder)
                        }
                    }
                }else {
                    onclicklinner.setError(t?.m_info!!,false)
                }

            }

        })

    }


    private var page:Int=0
    private val num = 5
    override fun LoadDateConstru(onclicklinner: InterfaceMa<String>) {///初始化第一次数据


    }












}